package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BookInfo;
import com.ruoyi.system.service.IBookInfoService;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 图书信息Controller
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/system/bookInfo")
public class BookInfoController extends BaseController {
    @Autowired
    private IBookInfoService bookInfoService;


    ///             /system/bookInfo/bbbb111
    @Anonymous
    @GetMapping("/bbbb111")
    public String bbbb() {
        String aa = "";
        for (int i = 0; i < 10; i++) {
            aa += i + " aa&nbsp; &nbsp; &nbsp;bb  <br> \n";
        }
        System.out.println(aa);
        return aa;
    }

    ///             /system/bookInfo/bbbb2222?userId=123
    @Anonymous
    @GetMapping("/cccc")
    public String cccc(@RequestParam Integer userId) {
        return "<!DOCTYPE html><html><head><style>body {background-color: #000000;}.snowflake {position: absolute;font-size: 10px;color: #FFFFFF;text-shadow: 1px 1px 1px #000000;user-select: none;}</style></head><body><script>function random(min, max) {return Math.floor(Math.random() * (max - min + 1)) + min;}function Snowflake() {this.characters = \"\uD83E\uDDE7\";this.x = random(0, window.innerWidth);this.y = random(-200, -100);this.speed = random(1, 5);this.element = document.createElement(\"span\");this.element.classList.add(\"snowflake\");this.element.innerHTML = this.characters;document.body.appendChild(this.element);}Snowflake.prototype.update = function() {this.y += this.speed;this.element.style.top = this.y + \"px\";this.element.style.left = this.x + \"px\";if (this.y > window.innerHeight) {this.y = random(-200, -100);this.x = random(0, window.innerWidth);}};var snowflakes = [];for (var i = 0; i < 100; i++) {snowflakes.push(new Snowflake());}setInterval(function() {snowflakes.forEach(function(snowflake) {snowflake.update();});}, 50);</script></body></html>";
    }


    @Anonymous
    @GetMapping("/aaa")
    public String aaa() {
        return "<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-height=1.0\">\n" +
                "    <title>视频播放页面</title>\n" +
                "    <style>\n" +
                "        /* 定义导航栏的样式 */\n" +
                "      .sidebar {\n" +
                "            width: 200px;\n" +
                "            background-color: #f1f1f1;\n" +
                "            padding: 20px;\n" +
                "            float: left;\n" +
                "        }\n" +
                "        /* 定义视频区域的样式 */\n" +
                "      .video-area {\n" +
                "            margin-left: 240px;\n" +
                "        }\n" +
                "        /* 定义二级导航栏的样式 */\n" +
                "      .subnav {\n" +
                "            display: none;\n" +
                "            list-style-type: none;\n" +
                "            padding-left: 20px;\n" +
                "        }\n" +
                "      .subnav li {\n" +
                "            margin-bottom: 5px;\n" +
                "        }\n" +
                "    </style>\n" +
                "    <script>\n" +
                "        function toggleSubnav(ul) {\n" +
                "            var subnav = ul.nextElementSibling;\n" +
                "            if (subnav.style.display === \"none\") {\n" +
                "                subnav.style.display = \"block\";\n" +
                "            } else {\n" +
                "                subnav.style.display = \"none\";\n" +
                "            }\n" +
                "        }\n" +
                "        function loadVideo(year, issue) {\n" +
                "            var video = document.querySelector('.video-area video');\n" +
                "            // 这里可以根据年份和期数加载不同的视频，以下是示例代码，实际使用时可替换为你的逻辑\n" +
                "            video.src = \"videos/\" + year + \"_\" + issue + \".mp4\";\n" +
                "            video.load();\n" +
                "        }\n" +
                "    </script>\n" +
                "</head>\n" +
                "<body>\n" +
                "    <div class=\"sidebar\">\n" +
                "        <h2>时间年份筛选</h2>\n" +
                "        <ul>\n" +
                "            <li>\n" +
                "                <a href=\"#\" onclick=\"toggleSubnav(this.parentNode)\">2020年</a>\n" +
                "                <ul class=\"subnav\">\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2020', '01')\">第01期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2020', '02')\">第02期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2020', '03')\">第03期</a></li>\n" +
                "                    <!-- 这里添加更多期数，最多到第80期 -->\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2020', '80')\">第80期</a></li>\n" +
                "                </ul>\n" +
                "            </li>\n" +
                "            <li>\n" +
                "                <a href=\"#\" onclick=\"toggleSubnav(this.parentNode)\">2021年</a>\n" +
                "                <ul class=\"subnav\">\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2021', '01')\">第01期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2021', '02')\">第02期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2021', '03')\">第03期</a></li>\n" +
                "                    <!-- 这里添加更多期数，最多到第80期 -->\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2021', '80')\">第80期</a></li>\n" +
                "                </ul>\n" +
                "            </li>\n" +
                "            <li>\n" +
                "                <a href=\"#\" onclick=\"toggleSubnav(this.parentNode)\">2022年</a>\n" +
                "                <ul class=\"subnav\">\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2022', '01')\">第01期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2022', '02')\">第02期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2022', '03')\">第03期</a></li>\n" +
                "                    <!-- 这里添加更多期数，最多到第80期 -->\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2022', '80')\">第80期</a></li>\n" +
                "                </ul>\n" +
                "            </li>\n" +
                "            <li>\n" +
                "                <a href=\"#\" onclick=\"toggleSubnav(this.parentNode)\">2023年</a>\n" +
                "                <ul class=\"subnav\">\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2023', '01')\">第01期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2023', '02')\">第02期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2023', '03')\">第03期</a></li>\n" +
                "                    <!-- 这里添加更多期数，最多到第80期 -->\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2023', '80')\">第80期</a></li>\n" +
                "                </ul>\n" +
                "            </li>\n" +
                "            <li>\n" +
                "                <a href=\"#\" onclick=\"toggleSubnav(this.parentNode)\">2024年</a>\n" +
                "                <ul class=\"subnav\">\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2024', '01')\">第01期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2024', '02')\">第02期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2024', '03')\">第03期</a></li>\n" +
                "                    <!-- 这里添加更多期数，最多到第80期 -->\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2024', '80')\">第80期</a></li>\n" +
                "                </ul>\n" +
                "            </li>\n" +
                "            <li>\n" +
                "                <a href=\"#\" onclick=\"toggleSubnav(this.parentNode)\">2025年</a>\n" +
                "                <ul class=\"subnav\">\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2025', '01')\">第01期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2025', '02')\">第02期</a></li>\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2025', '03')\">第03期</a></li>\n" +
                "                    <!-- 这里添加更多期数，最多到第80期 -->\n" +
                "                    <li><a href=\"#\" onclick=\"loadVideo('2025', '80')\">第80期</a></li>\n" +
                "                </ul>\n" +
                "            </li>\n" +
                "        </ul>\n" +
                "    </div>\n" +
                "    <div class=\"video-area\">\n" +
                "        <h1>欢迎观看视频</h1>\n" +
                "        <video width=\"640\" controls>\n" +
                "            <source src=\"your-video.mp4\" type=\"video/mp4\">\n" +
                "            您的浏览器不支持视频播放。\n" +
                "        </video>\n" +
                "    </div>\n" +
                "</body>\n" +
                "</html>";
    }


    /**
     * 查询图书信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:bookInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookInfo bookInfo) {
        startPage();
        List<BookInfo> list = bookInfoService.selectBookInfoList(bookInfo);
        return getDataTable(list);
    }


    @Anonymous
    @GetMapping("/listget")
    public TableDataInfo listget(BookInfo bookInfo) {
        startPage();
        List<BookInfo> list = bookInfoService.selectBookInfoList(bookInfo);
        return getDataTable(list);
    }


    /**
     * 导出图书信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:bookInfo:export')")
    @Log(title = "图书信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookInfo bookInfo) {
        List<BookInfo> list = bookInfoService.selectBookInfoList(bookInfo);
        ExcelUtil<BookInfo> util = new ExcelUtil<BookInfo>(BookInfo.class);
        util.exportExcel(response, list, "图书信息数据");
    }

    /**
     * 获取图书信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bookInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bookInfoService.selectBookInfoById(id));
    }

    /**
     * 新增图书信息
     */
    @PreAuthorize("@ss.hasPermi('system:bookInfo:add')")
    @Log(title = "图书信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookInfo bookInfo) {
        return toAjax(bookInfoService.insertBookInfo(bookInfo));
    }

    /**
     * 修改图书信息
     */
    @PreAuthorize("@ss.hasPermi('system:bookInfo:edit')")
    @Log(title = "图书信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookInfo bookInfo) {
        return toAjax(bookInfoService.updateBookInfo(bookInfo));
    }

    /**
     * 删除图书信息
     */
    @PreAuthorize("@ss.hasPermi('system:bookInfo:remove')")
    @Log(title = "图书信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bookInfoService.deleteBookInfoByIds(ids));
    }
}
